<template>
    <div class="box">
        <el-row>
            <el-col :span="22" :push="1">
                <div class="grid-content bg-purple">
                    <div class="box_text">
                        添加油卡消费记录
                        <el-divider></el-divider>
                    </div>
                    <div style="margin-top: 20px; margin-left: 40px; width: 500px">
                        <el-form>
                            <el-form-item label="选择油卡">
                                <el-select v-model="form.fuelcardName">
                                    <el-option v-for="item in options" :key="item.id" :label="item.fuelcardName"
                                        :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="油卡类型">
                                <el-select v-model="form.fuelcardType" placeholder="油卡类型">
                                    <span v-for="(item, index) in carStates" :key="index">
                                        <el-option :label="item.label" :value="item.value"></el-option>
                                    </span>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="消费时间">
                                <el-date-picker v-model="form.releaseTime" type="date"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期">
                                </el-date-picker>
                            </el-form-item>
                            <el-form-item label="消费余额">
                                <el-input v-model="form.releaseAmount" style="width: 100px;"></el-input>元
                            </el-form-item>
                            <el-form-item label="消费人">
                                <!-- 选择负责人start -->
                                <div class="avatar-uploader">
                                    <!-- 选中负责人后展示start -->
                                    <div v-if="selectedUser != ''">
                                        <img :src="selectedUser.icon" class="avatar" @click="headPage = true">
                                        <span style="position: relative;top: -17px;left: 20px;">{{ selectedUser.nickName
                                            }}
                                            <span style="margin-left: 26px;cursor: pointer;" @click="deUser">X</span>
                                        </span>
                                    </div>
                                    <!-- 选中负责人后展示end -->
                                    <!-- 负责人未选中展示 -->
                                    <i v-else @click="headPage = true" class="el-icon-plus avatar-uploader-icon"></i>
                                </div>
                            </el-form-item>

                            <el-dialog v-loading="loading" element-loading-text="拼命加载中"
                                element-loading-spinner="el-icon-loading"
                                element-loading-background="rgba(0, 0, 0, 0.8)" :visible.sync="headPage" width="50%"
                                :show-close="false">
                                <el-breadcrumb separator-class="el-icon-arrow-right">
                                    <!-- 步骤条start -->
                                    <el-breadcrumb-item v-for="(value, index) in headNavs" :key="index + 'e'"
                                        @click="upNav(index)">
                                        <el-button v-if="persons.id == undefined" size="mini" style="border: 0px;"
                                            @click="upNav(index)">{{ value }}</el-button>
                                    </el-breadcrumb-item>
                                    <!-- 步骤条end -->
                                    <br>
                                    <br>
                                    <br>
                                    <!-- 展示右边所选中的用户start -->
                                    <div style="float: right;margin-top: -70px;margin-right:30%;color: black;">
                                        已选择<span v-if="selectedUser != ''">1</span><span v-else>0</span>位联系人
                                        <br>
                                        <br>
                                        <br>
                                    </div>
                                    <!-- 展示选中的用户 -->
                                    <div v-if="selectedUser != ''" class="architecture"
                                        style="height: 50px;float: right;    position: relative;top: 12px;right: 50px;">
                                        <img style="width: 30px;height: 30px;position: relative;top: 10px;"
                                            :src="selectedUser.icon" />
                                        <span
                                            style="margin-left: 17%;color: black;color: black;font-size: 10px;display: block;margin-top: -20px;">
                                            {{ selectedUser.nickName }}<br><br>
                                            {{ selectedUser.tposition.deptName }}
                                            <span
                                                style="float: right;margin-top: -10px;margin-right: 20px;cursor: pointer;"
                                                @click="deUser">X</span>
                                        </span>

                                    </div>
                                    <!-- 展示右边所选中的用户end -->
                                    <!-- 展示左边信息start -->
                                    <!-- 展示部门和人数start -->
                                    <div class="architecture" style="line-height: 39px;"
                                        v-for="(value, perIndex) in persons" :key="perIndex"
                                        @click="selectArchitecture(value.deptName)">
                                        <div class="log">
                                            <img
                                                src="https://cdn7.axureshop.com/demo2023/2236859/images/%E8%AF%B7%E5%81%87/u2303.svg" />
                                        </div>
                                        <span style="margin-left: 5%;color: black;">
                                            {{ value.deptName }}
                                        </span>
                                        &nbsp;&nbsp;&nbsp;({{ value.deptCount }})
                                        <span style="float: right;margin-right: 20px;">
                                            ＞
                                        </span>
                                    </div>
                                    <!-- 展示部门和人数end -->
                                    <br>
                                    <!-- 展示当前所选部门的所有用户start -->
                                    <div v-if="users.length != 0">
                                        <div :class="[selectArchitectureCss != userIndex ? 'architecture' : '', selectArchitectureCss == userIndex ? 'architectureActe' : '']"
                                            style="height: 50px;" v-for="(myUser, userIndex) in users" :key="userIndex"
                                            @click="selectUser(userIndex)">
                                            <el-radio style="width: 80%;height: 100%;" v-model="selectId"
                                                :label="userIndex">
                                                &nbsp;&nbsp;&nbsp;
                                                <img style="width: 30px;height: 30px;position: relative;top: 10px;"
                                                    :src="myUser.icon" />
                                                <span
                                                    style="margin-left: 5%;color: black;font-size: 10px;float: left;position: relative;top: 12px;left: 110px;">
                                                    {{ myUser.nickName }}<br><br>
                                                    {{ myUser.tposition.deptName }}
                                                </span>

                                            </el-radio>
                                            <span>
                                                ＞
                                            </span>
                                        </div>
                                    </div>
                                    <!-- 展示当前所选部门的所有用户start -->
                                    <!-- 展示左边信息end -->

                                </el-breadcrumb>

                                <!-- 竖直分割线 -->
                                <div class="myHr"></div>


                                <span slot="footer" class="dialog-footer">
                                    <el-button @click="headPage = false">取 消</el-button>
                                    <el-button type="primary" @click="headPage = false">确 定</el-button>
                                </span>
                            </el-dialog>
                            <!-- 选择负责人end -->
                            <el-form-item label="车辆">
                                <el-select v-model="form.releaseCarnumber" placeholder="选择车辆">
                                    <span v-for="(item, index) in carNumbers" :key="index">
                                        <el-option :label="item.carNumber" :value="item.id"></el-option>
                                    </span>
                                </el-select>
                            </el-form-item>
                            <el-form-item>
                                <el-button type="primary" @click="onSubmit">立即提交</el-button>
                                <el-button @click="back">取消</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import axios from "axios";
export default {
    data() {
        return {
            form: {
                type:1
            },
            options: {},
            carStates: [{ value: "0", label: "中石油" },
            { value: "1", label: "中海油" },
            { value: "2", label: "中石化" },
            { value: "3", label: "其他" }],
            carNumbers:{},
             // 获取负责人start
             headPage: false,//开启选择负责人页面
            headNavs: ["组织架构"],//步骤条
            persons: [],//部门和部门人数
            users: [],//所选部门的人员
            loading: false,//加载开启和关闭
            selectArchitectureCss: -1,//选中指定行后开启指定的css
            selectId: -1,//单选框
            selectedUser: "",//选中的用户
            replacementCard: {
                rulesName: "",
                replacementHead: "",
                replacementType: [],
                card: false,
            },
            //  获取负责人end
        };
    },
    created() {
        this.getrelease()
        this.getDept();
        this.getCarNumber()
    },
    methods: {
        back(){
            this.$router.go(-1)
        },
        //提交
        onSubmit() {
            axios.post("carfuelcardrelease/addtCarFuelCardRelease",this.form).then((res)=>{
                console.log(res)
                if(res.data.code === 200){
                    this.$message.success(res.data.data)
                    this.form ={}
                    this.selectedUser = ""
                    this.$router.go(-1)
                }
            })
        },
        //查询油卡信息
        getrelease() {
            axios.post("carfuelcard/findTCarFuelcard?pageSize=" + 100 + "&pageNum=" + 1, {}).then((res) => {
                console.log(res)
                this.options = res.data.data.records
            })
        },
        // 负责人start
        // 更新步骤条
        upNav(index) {
            this.headNavs = this.headNavs.slice(0, index + 1);
            if ("组织架构" == this.headNavs) {
                this.loading = true;
                this.users = [];
                this.getDept();
            }
        },
        // 获取部门及部门人数
        getDept() {
            this.selectId = -1;
            this.deUser();
            axios.post("/ReplacementCard/findDept")
                .then((res) => {
                    this.persons = res.data.rows;
                    this.loading = false;
                })
        },
        //查询车牌号
        getCarNumber() {
            axios.get("/car/getCarNumber").then((res) => {
                console.log(res)
                this.carNumbers = res.data.data
            })
        },
        // 获取所选择部门的用户信息
        selectArchitecture(value) {
            this.loading = true;
            this.persons = [];
            this.headNavs.push(value);
            var data = new FormData();
            data.append("name", value)
            axios.post("/ReplacementCard/findUserAndDept", data)
                .then((res) => {
                    this.users = res.data.rows;
                    if (this.users != []) {
                        this.loading = false;
                    }
                })

        },
        // 是否允许补卡更改重置和他相关联的值
        reset() {
            if (!this.replacementCard.card) {
                this.replacementCard.replacementCount = undefined;
                this.replacementCard.time = undefined;
            }

        },

        // 选中用户
        selectUser(index) {
            this.selectArchitectureCss = index;
            this.selectedUser = this.users[index];
            this.form.releaseUser = this.selectedUser.id;
        },
        // 删除用户
        deUser() {
            this.selectId = -1;
            this.selectedUser = "";
            this.selectArchitectureCss = -1;
            this.form.releaseUser = "";
        },
        // 负责人end
    }
};
</script>

<style scoped>
/* element-ui样式 */
.el-row {
    margin-bottom: 10px;

    &:last-child {
        margin-bottom: 0;
    }
}

.el-col {
    border-radius: 4px;
}

.bg-purple {
    background: #fff;
    border-radius: 10px;
}

/* 自定义样式 */
/* * {
      margin: 0px;
      padding: 0px;
    } */
.box {
    width: 98%;
    height: 100%;
    margin: auto;
    /* background-color: red; */
}

.box_text {
    padding-top: 20px;
    /* padding-left: 40px; */
    margin-left: 40px;
    font-size: 16px;
}
/* 获取负责人start */
.avatar-uploader-icon[data-v-c59672b0] {
    border: 1px solid rgba(198, 201, 208, 1);
    background-color: rgba(248, 248, 248, 1);
    border-radius: 50%;
}

.avatar-uploader-icon {
    font-size: 20px;
    color: #8c939d;
    width: 50px;
    height: 50px;
    line-height: 50px;
    text-align: center;
}


.architecture {
    width: 271px;
    height: 39px;
    padding-left: 20px;
    border-radius: 5px;
}

.architecture:hover {
    background-color: #f8f8f8;
}

.architectureActe {
    width: 271px;
    height: 39px;
    line-height: 39px;
    padding-left: 20px;
    border-radius: 5px;
    background-color: rgba(231, 244, 255, 1);
    ;
}

/* 竖着的水平线 */
.myHr {
    border-left: 2px solid#989DAA;
    ;
    height: 100%;
    left: 48%;
    top: 0px;
    position: absolute;
}

.log {
    width: 27px;
    height: 27px;
    background-color: rgba(158, 208, 255, 1);
    float: left;
    position: relative;
    top: 15%;
    border-radius: 50%;
}

.log img {
    width: 13px;
    height: 13px;
    position: relative;
    bottom: 15%;
    left: 25%;
}

/* 获取负责人end */
</style>